import 'package:flutter/material.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:xinxuan/common/appbar_util.dart';
import 'package:xinxuan/common/network_image_util.dart';
import 'package:xinxuan/controllers/my_controller/space_statistics_detail_page_controller.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/utils/refresh_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SpaceStatisticsDetailPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: pageBgColor,
      appBar: AppBarUtil(
        title: '空间统计',
        backgroundColor: bgWhiteColor,
      ),
      body: GetBuilder<SpaceStatisticsDetailPageController>(
        init: SpaceStatisticsDetailPageController(),
        builder: (controller) {
          return RefreshUtil.easyRefresh(
            onRefresh: () async {
              controller.getTeamMembers();
            },
            onLoad: () async {
              controller.onloadTeamMembers();
            },
            slivers: controller.teamMembersVo.value.data!.map((item) {
              return SliverToBoxAdapter(
                child: Container(
                  margin: EdgeInsets.only(top: 12.h),
                  padding: EdgeInsets.symmetric(horizontal: 16.w),
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(5.w),
                      color: bgWhiteColor
                    ),
                    child: Container(
                      padding: EdgeInsets.symmetric(horizontal: 8.w),
                      child: Column(
                        children: [
                          Container(
                            padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 16.h),
                            decoration: BoxDecoration(
                              border: Border(
                                bottom: BorderSide(
                                  width: .5.h,
                                  color: lineColor
                                )
                              )
                            ),
                            child: Row(
                              children: [
                                NetworkImageUtil(
                                  url: '',
                                  nickname: '${item.nickname}', 
                                  width: 36.w, 
                                  height: 36.w,
                                  showShadow: false,
                                ),
                                SizedBox(width: 12.w),
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                      '${item.nickname} ${item.mobile}',
                                      style: TextStyle(
                                        color: textBlackColor,
                                        fontSize: 16.sp
                                      ),
                                    ),
                                    SizedBox(height: 6.h),
                                    Text(
                                      '${item.createdAt}',
                                      style: TextStyle(
                                        color: textSubtitleColor,
                                        fontSize: 12.sp
                                      ),
                                    )
                                  ],
                                )
                              ],
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 4.w, right: 4.w, bottom: 16.h),
                            child: Column(
                              children: [
                                _valueItem(title: '7日订单量', value: '${item.sevenDayOrderNum}'),
                                _valueItem(title: '今日订单', value: '${item.sevenDayOrderNum}'),
                                _valueItem(title: '当日购买金额', value: '${item.sevenDayOrderNum}'),
                                _valueItem(title: '累计收益', value: '${item.sevenDayOrderNum}'),
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                ),
              );
            }).toList()
          );
        }, 
      ),
    );
  }

  Widget _valueItem({required String title, required String value}) {
    return Container(
      margin: EdgeInsets.only(top: 16.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            title,
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
            style: TextStyle(
              color: textSubtitleColor,
              fontSize: 14.sp,
            ),
          ),
          SizedBox(height: 6.h),
          Text(
            value,
            overflow: TextOverflow.ellipsis,
            maxLines: 1,
            style: TextStyle(
              color: textBlackColor,
              fontSize: 16.sp,
              fontWeight: FontWeight.bold
            ),
          )
        ],
      ),
    );
  }
}